'use strict'

const fs = require('fs')
const { Sequelize, DataType, Op } = require('sequelize');

const sequelize = new Sequelize('hcg', 'postgres', 'withyou123..', {
    host: 'www.guanqing.top',
    dialect: 'postgres'
})

let files = fs.readdirSync(__dirname)

let resFiles = files.filter(item => {
    return item.endsWith('.js') && item !== 'index.js'
})
let resObj = {};

resFiles.forEach(item => {
    let modelName = item.replace('.js', '');
    let temObj = require(__dirname + '/' + item);
    let tableName = modelName.toLowerCase();
    resObj[modelName] = sequelize.define(tableName, temObj);
})

resObj.Op = Op;
resObj.sync = async () => {
    sequelize.sync({ force: true }).then(() => {
        resObj.product.bulkCreate([
            {
                title: 'Js',
                zaiyao: 'js',
                body: 'js基础',
                type:'js',
                author: '莫大神'
            },
            {
                title: '敲代码',
                zaiyao: 'js',
                body: 'js基础',
                type:'js',
                author: '大神带带我'
            },
            {
                title: 'Js',
                zaiyao: 'js',
                body: 'js基础',
                type:'js',
                author: '莫大神'
            },
           
        ])
    })
}

module.exports = resObj;